package com.aistar.service.impl;

import com.aistar.mapper.ProgramCollectMapper;
import com.aistar.pojo.ProgramCollect;
import com.aistar.pojo.ProgramCollectExample;
import com.aistar.service.ProgramCollectService;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProgramCollectServiceImpl implements ProgramCollectService {
    private final ProgramCollectMapper mapper;

    @Autowired
    public ProgramCollectServiceImpl(ProgramCollectMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public ServerResponse getByProgramIdAndCustomerId(Integer programId, Integer customerId) {
        ProgramCollectExample example = new ProgramCollectExample();
        example.createCriteria().andCustomerIdEqualTo(customerId).andProgramIdEqualTo(programId);
        List<ProgramCollect> programCollects = mapper.selectByExample(example);
        if (programCollects.size()>0 && programCollects != null){
            return ServerResponse.getSuccess(programCollects.get(0));
        }
        return ServerResponse.getFailed();
    }
}
